using System;
using System.Collections.Generic;
using System.Text;
using DTO.AP;
using DTO.PO;
using DAO.AP;
using DAO.PO;
using DAO;

namespace BUS
{
    public class Account
    {
        public void CreateDoc(int poBatchNum, DateTime date, char type, string receiptName, int total, int vendorID)
        {
            // Update lo hang` sang trang thai' U
            BatchDAO batchDAO = new BatchDAO();
            if (batchDAO.GetBatch(poBatchNum))
            {
                batchDAO.UpdateStatus(poBatchNum, 'U');
            }
            // tao lo cong no.
            APBatch batch = new APBatch();
            batch.Type = type;
            batch.ReceiptName = receiptName;
            batch.TotalQty = total;

            APBatchDAO apBatchDAO = new APBatchDAO();
            apBatchDAO.InsertAPBatch(batch);

            // tao doc
            APDoc doc = new APDoc();
            doc.Date = date;
            doc.Type = type;
            doc.TotalMoney = total;
            doc.Payment = 0;
            doc.VendorId = vendorID;
            doc.APBatchNum = batch.BatchNum;

            APDocDAO apDocDAO = new APDocDAO();
            apDocDAO.InsertAPDoc(doc);
        }
    }
}
